package com.ws.controller;

import com.ws.entity.Goods;
import com.ws.entity.GoodsType;
import com.ws.service.GoodsService;
import com.ws.service.GoodsTypeService;
import com.ws.service.TeamService;
import com.ws.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/shop")
public class ShopController {

    @Autowired
    private GoodsService goodsService;

    @Autowired
    private GoodsTypeService goodsTypeService;

    @Autowired
    private TeamService teamService;

//    @RequestParam(value = "username",defaultValue = "",required = false) String username,
//    @RequestParam(value = "phone",defaultValue = "",required = false) String phone,
//    @RequestParam(value = "beginTime",defaultValue = "",required = false) String beginTime,
//    @RequestParam(value = "endTime",defaultValue = "",required = false) String endTime,
//    @RequestParam(value = "freeze",defaultValue = "",required = false) String freeze,

    @GetMapping("/goods-type/list/page")
    public Result getGoodsTypeListforPage(
            @RequestParam(value = "pno",defaultValue = "1",required = false) int pno,
            @RequestParam(value = "psize",defaultValue = "10",required = false) int psize,
            @RequestParam(value = "name",defaultValue = "",required = false) String name) {
        return goodsTypeService.getGoodsTypeListforPage(pno, psize, name);
    }

    @PutMapping("/goods-type/insert")
    public Result insertGoodsType(@RequestBody GoodsType goodsType) {
        return goodsTypeService.insertGoodsType(goodsType);
    }

    @GetMapping("/goods-type/find/id/{id}")
    public Result findGoodsTypeById(@PathVariable("id") Long id) {
        return goodsTypeService.findGoodsTypeById(id);
    }

    @PutMapping("/goods-type/update")
    public Result updateGoodsType(@RequestBody GoodsType goodsType) {
        return goodsTypeService.updateGoodsType(goodsType);
    }

    @DeleteMapping("/goods-type/delete/id/{id}")
    public Result deleteGoodsTypeById(@PathVariable("id") Long id) {
        return goodsTypeService.deleteGoodsTypeById(id);
    }

    @GetMapping("/goods-type/list/all")
    public Result getGoodsTypeAll() {
        return goodsTypeService.getGoodsTypeAll();
    }

    @GetMapping("/goods/list/page")
    public Result getGoodsListForPage(
            @RequestParam(value = "name",defaultValue = "",required = false) String name,
            @RequestParam(value = "goodsTypeId",required = false) Long goodsTypeId,
            @RequestParam(value = "isOnSale",required = false) Integer isOnSale,
            @RequestParam(value = "pno",defaultValue = "1",required = false) int pno,
            @RequestParam(value = "psize",defaultValue = "10",required = false) int psize) {
        return goodsService.getGoodsListForPage(name, goodsTypeId, isOnSale, pno, psize);
    }

    @PutMapping("/goods/insert")
    public Result insertGoods(@RequestBody Goods goods) {
        return goodsService.insertGoods(goods);
    }

    @GetMapping("/goods/find/id/{id}")
    public Result findGoodsById(@PathVariable("id") Long id) {
        return goodsService.findGoodsById(id);
    }
    @PutMapping("/goods/update")
    public Result updateGoods(@RequestBody Goods goods) {
        return goodsService.updateGoods(goods);
    }

    @DeleteMapping("/goods/delete/id/{id}")
    public Result deleteGoodsById(@PathVariable("id") Long id) {
        return goodsService.deleteGoodsById(id);
    }

    @GetMapping("/goods/set/onsale")
    public Result setGoodsOnsale(@RequestParam("id") Long id, @RequestParam("isOnSale") Integer isOnSale) {
        return goodsService.setGoodsOnsale(id, isOnSale);
    }

    @GetMapping("/goods/list/hot")
    public Result getHotGoods() {
        return goodsService.getHotGoods();
    }

    @GetMapping("/team/list/page")
    public Result getTeamListForPage(
            @RequestParam(value = "type",required = false) Integer type,
            @RequestParam(value = "isOnSale",required = false) Integer isOnSale,
            @RequestParam(value = "pno",defaultValue = "1",required = false) int pno,
            @RequestParam(value = "psize",defaultValue = "5",required = false) int psize) {
        return teamService.getTeamListForPage(type, isOnSale, pno, psize);
    }





















}
